package com.zcc.makingfriend.controller;

import com.zcc.makingfriend.dao.Report;
import com.zcc.makingfriend.service.ReportService;
import com.zcc.makingfriend.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zcc
 */
@Api(tags = "举报管理")
@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    ReportService reportService;

    @ApiOperation("举报文章")
    @PostMapping("/article")
    public Result reportArticle(@RequestBody Report report) {
        int i = reportService.addReport(report);
        if (i == 1) {
            return Result.success("举报成功");
        }
        return Result.fail("举报失败");
    }

    @ApiOperation("通过文章id找到举报信息")
    @GetMapping("/getReportByArticleId/{articleId}")
    public Result getReportByArticleId(@PathVariable Long articleId) {
        return Result.success(reportService.findReportByArticleId(articleId));
    }

    @ApiOperation("统计未处理的举报信息")
    @GetMapping("/countReportUnread")
    public Result countReportUnread() {
        return Result.success(reportService.countUnRead());
    }

    @ApiOperation("阅读举报信息")
    @GetMapping("/readByArticleId/{articleId}")
    public Result readByArticleId(@PathVariable Long articleId) {
        return Result.success(reportService.readByArticleId(articleId));
    }


}
